//
//  ZBDebugCollectionViewCell.m
//  DevDemo
//
//  Created by BO ZHOU on 2021/5/6.
//

#import "ZBDebugCollectionViewCell.h"
#import "ZBBaseDebugView.h"

@interface ZBDebugCollectionViewCell()


@property (nonatomic, strong) UIImageView* iconView;

@property (nonatomic, strong) UILabel* titleLabel;



@end


@implementation ZBDebugCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self.contentView addSubview:self.iconView];
        [self.contentView addSubview:self.titleLabel];
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    CGFloat iconWH = 50;
    self.iconView.frame = CGRectMake(self.frame.size.width/2 - iconWH/2, 14, iconWH, iconWH);
    self.titleLabel.frame = CGRectMake(0, CGRectGetMaxY(self.iconView.frame) + 2, self.frame.size.width, 30);
}


- (void)setModel:(ZBDebugViewSourceModel *)model {
    _model = model;
    
    self.iconView.image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@", SelfBundle(), model.iconName]];
    self.titleLabel.text = model.title;
}

- (UIImageView *)iconView {
    if (_iconView == nil) {
        _iconView = [UIImageView new];
    }
    return _iconView;
}

- (UILabel *)titleLabel {
    if (_titleLabel == nil) {
        _titleLabel = [UILabel new];
        _titleLabel.font = [UIFont systemFontOfSize:14];
        _titleLabel.textColor = [UIColor redColor];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _titleLabel;
}

@end
